package com.example.project3.controller;

import com.example.project3.entity.GroupChat;
import com.example.project3.service.impl.GroupChatServiceImpl;
import com.example.project3.util.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName IMController .java
 * @Description empty
 * @Author LiuJinyu
 * @Date 2023/6/6 21:26
 * @Version 1.0
 */
@RestController
@RequestMapping("/IM")
public class IMController {

    private com.example.project3.service.im.IMService IMService;
    private GroupChatServiceImpl groupChatServiceImpl;

    @PostMapping("/group/send")
    public API groupSendMessage(@RequestBody GroupChat groupChat) throws IOException {
        IMService.sendGroup(groupChat);
        return API.success(groupChat);
    }

    @GetMapping("/get")
    public API getGroupChatHistory(@RequestParam Integer projectId) {
        Map<String, Object> query = new HashMap<>();
        query.put("project_id", projectId);
        return API.success(groupChatServiceImpl.listByMap(query));
    }

    @Autowired
    public void setIMService(com.example.project3.service.im.IMService imService) {
        this.IMService = imService;
    }

    @Autowired
    public void setGroupChatServiceImpl(GroupChatServiceImpl groupChatServiceImpl) {
        this.groupChatServiceImpl = groupChatServiceImpl;
    }
}
